﻿using System;
using System.Data;
using QLTH_DTO;

namespace QLTH_DATASSECC
{
    public class clsNamHocDA : ConnectionData.clsKetNoi
    {
        String _sql = "";
        public DataTable DanhSachNamHoc()
        {
            _sql = "SELECT MANH, TENNAMHOC FROM NAMHOC";
            return Load_DataTable(_sql);
        }

        public string kiemtraNH(String _dk)
        {
            _sql = "SELECT MANH FROM NAMHOC WHERE MANH='" + _dk + "'";
            if (laymadk(_sql) == null)
                return null;
            return laymadk(_sql).ToString();
        }
        public int Them_nh(clsNamHocDTO nh)
        {
            int namepara = 3;
            String[] name = new String[namepara];
            Object[] values = new Object[namepara];
            name[0] = "@Manh"; values[0] = nh.Manh;
            name[1] = "@NamHoc"; values[1] = nh.Namhoc;
            name[2] = "@Trangthai"; values[2] = nh.Trangthai;
            _sql = "INSERT INTO NAMHOC VALUES(@Manh,@Namhoc,@Trangthai)";
            return Nonquery(_sql,name,values,namepara);
        }
        public int CapNhat_nh(clsNamHocDTO nh)
        {
            int namepara = 3;
            String[] name = new String[namepara];
            Object[] values = new Object[namepara];
            name[0] = "@Manh"; values[0] = nh.Manh;
            name[1] = "@NamHoc"; values[1] = nh.Namhoc;
            name[2] = "@Trangthai"; values[2] = nh.Trangthai;
            _sql = "UPDATE NAMHOC SET TRANGTHAI = @Trangthai WHERE MANH =@Manh";
            return Nonquery(_sql, name, values, namepara);
        }
        public int Capnhat_nhALL(clsNamHocDTO nh)
        {
            int namepara = 1;
            String[] name = new String[namepara];
            Object[] values = new Object[namepara];
            name[0] = "@Trangthai"; values[0] = nh.Trangthai;
            _sql = "UPDATE NAMHOC SET TRANGTHAI = @Trangthai";
            return Nonquery(_sql,name,values,namepara);
        }

        public int Xoa_namhoc(clsNamHocDTO nh)
        {
            int namepara = 1;
            String[] name = new String[namepara];
            Object[] values = new Object[namepara];
            name[0] = "@Manh"; values[0] = nh.Manh;
            _sql = "DELETE NAMHOC WHERE MANH = @Manh";
            return Nonquery(_sql,name,values,namepara);
        }
        public DataTable manhHientai()
        {
            _sql = "SELECT MANH,TENNAMHOC FROM NAMHOC WHERE TRANGTHAI = 1";
            return Load_DataTable(_sql) ;
        }
    }
}
